package strategy1.pay;

import cn.hutool.core.util.EnumUtil;
import org.springframework.stereotype.Component;

/**
 * @author ycd0075
 * @date 2023-04-27 18:08
 */
@Component
public class PaymentStrategyHandler {

    public Boolean pay(String payBody) {
        if (!EnumUtil.contains(PayStrategyEnum.class, payBody)) {
            throw new IllegalArgumentException("不支持的支付方式!");
        }
        // 1.获取支付策略对象
        IPayment payStrategy = PaymentFactory.getPayStrategy(payBody);
        // 2.获取支付策略上下文
        PaymentContext paymentContext = new PaymentContext(payStrategy);
        // 3.进行支付
        return paymentContext.pay(payBody);
    }

}
